package pl.edu.politechnika.zio.fbapp.business.entity.repository;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;

import pl.edu.politechnika.zio.fbapp.business.entity.Message;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;

@Repository
public class MessageDAO implements IMessageDAO {
    private Objectify oby;

    @Inject
    public MessageDAO(ObjectifyFactory objectifyFactory) {
        this.oby = objectifyFactory.begin();
    }

    public MessageDAO() {
    }

    @Override
    public List<Message> findAll() {
        return oby.query(Message.class).list();
    }

    @Override
    public Message findById(Long id) {
        return oby.find(Message.class, id);
    }

    @Override
    public Key<Message> create(Message object) {
        return oby.put(object);
    }

    @Override
    public Key<Message> update(Message object) {
        return create(object);
    }

    @Override
    public void remove(Message object) {
        oby.delete(object);
    }

    @Override
    public void removeById(Long id) {
        oby.delete(Message.class, id);
    }

}
